home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ 5⁄18⁄90 / 1286-Using THINK'S C & PA-May90 < prev    next >
Encoding:
Text File  |  1990-05-18  |  5.1 KB  |  205 lines  |  [TEXT/GEOL]

  1. Item    5421661                         14-May-90        08:25PDT
  2.  
  3. From:   TESLER                          Tesler, Larry
  4.  
  5. To:     MACAPP.TECH$                    MacApp Technical
  6.  
  7. cc:     TESLER                          Tesler, Larry
  8.  
  9. Sub:    Using THINK'S C & PASCAL
  10.  
  11. I converted a large MacApp program with C modules from MPW to THINK PASCAL & C.
  12.  
  13. To get it to work, below are listed some of the things I had to do that were
  14. not apparent from the documentation I read.
  15.  
  16.  
  17. PROBLEM 1:
  18.  
  19.    In INTERFACE of one unit:
  20.    TYPE
  21.    CategoryHandle  = ^CategoryPtr;
  22.    CategoryPtr = ^CategoryArray;
  23.    CategoryArray   = ARRAY[OffScreenPixel] OF PaletteIndex;
  24.  
  25.    In IMPLEMENTATION of another unit:
  26.    cat := CategoryHandle(NewPermHandle(256*SIZEOF(cat^^[0])));
  27.  
  28.    Problem:
  29.    256*SIZEOF(cat^^[0])) calculates the wrong answer.
  30.  
  31.    Workaround:
  32.    cat := CategoryHandle(NewPermHandle(256*LONGINT(512)));
  33.  
  34.    Note:
  35.    I'm not sure whether the following would have worked:
  36.    cat := CategoryHandle(NewPermHandle(256*LONGINT(SIZEOF(cat^^[0]))));
  37.  
  38.  
  39. PROBLEM 2:
  40.    In INTERFACE OF a unit:
  41.    ProfileResultArray = array [ 0 .. kMaxLogsPerProfile - 1 ] of EXTENDED;
  42.  
  43.    Problem:
  44.    Constant expression kMaxLogsPerProfile-1 is not allowed.
  45.  
  46.    Workaround:
  47.    ProfileResultArray = array[0..1] of EXTENDED;
  48.  
  49.  
  50. PROBLEM 3:
  51.    In INTERFACE OF a unit:
  52.    TYPE
  53.    RecordOfUnwrappedViews = record
  54.    unwrappedView: TUnwrappedView;
  55.    colorScaleView: TColorScaleView;
  56.    depthScaleView: TDepthScaleView;
  57.    azimuthScaleView: TAzimuthScaleView;
  58.    end;
  59.    ...
  60.    TUnwrappedView = OBJECT(TOffScreenView)
  61.    fAssociatedViews:   RecordOfUnwrappedViews;
  62.  
  63.    Problem:
  64.    Forward reference to TUnwrappedView from RecordOfUnwrappedViews illegal
  65.    and vice versa
  66.  
  67.    Workaround:
  68.    Deleted line:
  69.    unwrappedView: TUnwrappedView;
  70.    Moved type RecordOfUnwrappedViews after type TUnwrappedView
  71.  
  72.  
  73. PROBLEM 4:
  74.    In INTERFACE OF a unit:
  75.    type
  76.    HistogramList = record
  77.    numberOfHistograms: longint;
  78.    histogramSize: longint;
  79.    thehistogramdata: packed array[0..2147483] of longint;
  80.    end;
  81.    HistogramListP = ^HistogramList;
  82.    HistogramListH = ^HistogramListP;
  83.  
  84.    Problem:
  85.    2147483 not allowed as upper bound
  86.    (even though only HistogramListH is referenced later)
  87.  
  88.    Workaround:
  89.    thehistogramdata: packed array[0..1000] of longint;
  90.  
  91.  
  92. PROBLEM 5:
  93.    In a THINK C module:
  94.    Tried to call atan, sqrt, hypot, malloc, free, memccpy, fflush, etc.
  95.  
  96.    Problem:
  97.    C and Pascal libraries differ in contents
  98.    C and Pascal libraries have duplicate symbols
  99.  
  100.    Workaround:
  101.    Added to one of my Pascal units:
  102.    procedure take_atan (var x, y: double);
  103.     begin
  104.     y := arctan(x);
  105.     end;
  106.  
  107.     procedure take_sqrt (var x, y: double);
  108.     begin
  109.     y := sqrt(x);
  110.     end;
  111.  
  112.    Defined my own atanf, sqrtf, hypot, memccpyf as follows:
  113.    pascal extern void take_atan(double* x, double* y);
  114.  
  115.    double atanf(double x)
  116.    {
  117.    double z;
  118.    take_atan(&x, &z);
  119.    return(z);
  120.    }
  121.  
  122.    pascal extern void take_sqrt(double* x, double* y);
  123.  
  124.    double sqrtf(double x)
  125.    {
  126.    double z;
  127.    take_sqrt(&x, &z);
  128.    return(z);
  129.    }
  130.  
  131.    double hypot(double x, double y)
  132.    {
  133.    return(sqrtf(x*x+y*y));
  134.    }
  135.  
  136.    char* memccpyf(char *dest, char *source, char c, size_t n)
  137.    {
  138.    long i;
  139.    for(i=0;i<n;i++)
  140.    if((dest[i] = source[i])==c)
  141.    return(&dest[i+1]);
  142.    return(NULL);
  143.    }
  144.  
  145.    Called NewPermPtr and DisposPtr instead of malloc and free, after declaring:
  146.    pascal extern long NewPermPtr(long nbytes);
  147.  
  148.    Used MacHeaders to compile my C modules in THINK C.
  149.  
  150.   Got rid of all console and file I/O calls for now.
  151.  
  152.    Made my own C LibraryProject by copying and modifying ANSI-A4 as follows:
  153.    Copied and modified stdio.c as follows to avoid a duplicate __CLOSE message:
  154.    /*
  155.    int
  156.    __close(fp)
  157.    FILE *fp;
  158.    {
  159.    return((*fp->proc)(fp, 2));
  160.    }
  161.    */
  162.    Used the modified stdio.c in the modified ANSI-A4 LibraryProject
  163.    Built a Library from the modified ANSI-A4 LibraryProject
  164.    Added that Library to my Pascal Project along with a Library made from
  165.         my C modules
  166.  
  167.  
  168. PROBLEM 6:
  169.    In a THINK C module:
  170.    long max_num_attrs; { initialized to 40 later }
  171.    #define MAXFIELDWIDTH   16
  172.    typedef struct one_attribute
  173.    {
  174.    char type_code,element_size,attribute[MAXFIELDWIDTH+1],
  175.     unit[MAXFIELDWIDTH+1],*val_ptr;
  176.    long num_elements;
  177.    } attr_record, (*attr_ptr)[];
  178.    attr_ptr cblt_table;
  179.    cblt_table=(attr_ptr)NewPermPtr(sizeof(attr_record)*max_num_attrs);
  180.  
  181.    Problem:
  182.    "sizeof(attr_record)*max_num_attrs" generates a very large number
  183.  
  184.    Workaround:
  185.    cblt_table=(attr_ptr)NewPermPtr(2000);
  186.  
  187.    Note:
  188.    I'm not sure whether the following would have worked:
  189.    cblt_table=(attr_ptr)NewPermPtr(sizeof(attr_record)*(long)max_num_attrs);
  190.  
  191.  
  192. MISCELLANEOUS C CHANGES:
  193.    Changed all "int" to "long".
  194.    Changed all "extended" to "long double".
  195.    Would have changed all "double" to "short double" if I'd had any.
  196.    Had to stop using a conditionally compiled macro name as a type name.
  197.  
  198.  
  199. MISCELLANEOUS PASCAL CHANGES:
  200.    Eliminated all constant expressions used as:
  201.    array bounds
  202.    range bounds (m..n)
  203.    right sides of constant declarations
  204.  
  205.